﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BWindingMachine
{
    public partial class DebugForm : Form
    {
        public static bool left_back = false;
        public static bool right_back = false;
        public static bool left_into = false;
        public static bool right_into = false;

        public DebugForm()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Display();
        }

        private void Display()
        {

            if (Data.DataInput[1] == 1)
            {
                button21.BackColor = Color.Green;
            }
            else
            {
                button21.BackColor = Color.White;
            }
            if (Data.DataInput[2] == 1)
            {
                button23.BackColor = Color.Green;
            }
            else
            {
                button23.BackColor = Color.White;
            }
            if (Data.DataInput[3] == 1)
            {
                button81.BackColor = Color.Green;
            }
            else
            {
                button81.BackColor = Color.White;
            }
            if (Data.DataInput[4] == 1)
            {
                button79.BackColor = Color.Green;
            }
            else
            {
                button79.BackColor = Color.White;
            }
            if (Data.DataInput[5] == 1)
            {
                button26.BackColor = Color.Green;
            }
            else
            {
                button26.BackColor = Color.White;
            }
            if (Data.DataInput[6] == 1)
            {
                button24.BackColor = Color.Green;
            }
            else
            {
                button24.BackColor = Color.White;
            }
            if (Data.DataInput[7] == 1)
            {
                button28.BackColor = Color.Green;
            }
            else
            {
                button28.BackColor = Color.White;
            }
            if (Data.DataInput[8] == 1)
            {
                button27.BackColor = Color.Green;
            }
            else
            {
                button27.BackColor = Color.White;
            }
            if (Data.DataInput[9] == 1)
            {
                button48.BackColor = Color.Green;
            }
            else
            {
                button48.BackColor = Color.White;
            }
            if (Data.DataInput[10] == 1)
            {
                button46.BackColor = Color.Green;
            }
            else
            {
                button46.BackColor = Color.White;
            }
            if (Data.DataInput[11] == 1)
            {
                button44.BackColor = Color.Green;
            }
            else
            {
                button44.BackColor = Color.White;
            }
            if (Data.DataInput[12] == 1)
            {
                button41.BackColor = Color.Green;
            }
            else
            {
                button41.BackColor = Color.White;
            }
            if (Data.DataInput[13] == 1)
            {
                button39.BackColor = Color.Green;
            }
            else
            {
                button39.BackColor = Color.White;
            }
            if (Data.DataInput[14] == 1)
            {
                button38.BackColor = Color.Green;
            }
            else
            {
                button38.BackColor = Color.White;
            }
            if (Data.DataInput[15] == 1)
            {
                button57.BackColor = Color.Green;
            }
            else
            {
                button57.BackColor = Color.White;
            }
            if (Data.DataInput[16] == 1)
            {
                button55.BackColor = Color.Green;
            }
            else
            {
                button55.BackColor = Color.White;
            }
            if (Data.DataInput[17] == 1)
            {
                button54.BackColor = Color.Green;
            }
            else
            {
                button54.BackColor = Color.White;
            }
            if (Data.DataInput[18] == 1)
            {
                button52.BackColor = Color.Green;
            }
            else
            {
                button52.BackColor = Color.White;
            }
            if (Data.DataInput[19] == 1)
            {
                button50.BackColor = Color.Green;
            }
            else
            {
                button50.BackColor = Color.White;
            }
            if (Data.DataInput[20] == 1)
            {
                button49.BackColor = Color.Green;
            }
            else
            {
                button49.BackColor = Color.White;
            }
            if (Data.DataInput[21] == 1)
            {
                button78.BackColor = Color.Green;
            }
            else
            {
                button78.BackColor = Color.White;
            }
            if (Data.DataInput[22] == 1)
            {
                button76.BackColor = Color.Green;
            }
            else
            {
                button76.BackColor = Color.White;
            }
            if (Data.DataInput[23] == 1)
            {
                button74.BackColor = Color.Green;
            }
            else
            {
                button74.BackColor = Color.White;
            }
            if (Data.DataInput[24] == 1)
            {
                button73.BackColor = Color.Green;
            }
            else
            {
                button73.BackColor = Color.White;
            }
            if (Data.DataInput[25] == 1)
            {
                button72.BackColor = Color.Green;
            }
            else
            {
                button72.BackColor = Color.White;
            }
            if (Data.DataInput[26] == 1)
            {
                button70.BackColor = Color.Green;
            }
            else
            {
                button70.BackColor = Color.White;
            }
            if (Data.DataInput[27] == 1)
            {
                button69.BackColor = Color.Green;
            }
            else
            {
                button69.BackColor = Color.White;
            }
            if (Data.DataInput[28] == 1)
            {
                button67.BackColor = Color.Green;
            }
            else
            {
                button67.BackColor = Color.White;
            }
            if (Data.DataInput[29] == 1)
            {
                button65.BackColor = Color.Green;
            }
            else
            {
                button65.BackColor = Color.White;
            }
            if (Data.DataInput[30] == 1)
            {
                button64.BackColor = Color.Green;
            }
            else
            {
                button64.BackColor = Color.White;
            }
            if (Data.DataInput[31] == 1)
            {
                button63.BackColor = Color.Green;
            }
            else
            {
                button63.BackColor = Color.White;
            }
            if (Data.DataInput[32] == 1)
            {
                button61.BackColor = Color.Green;
            }
            else
            {
                button61.BackColor = Color.White;
            }
            if (Data.DataInput[33] == 1)
            {
                button60.BackColor = Color.Green;
            }
            else
            {
                button60.BackColor = Color.White;
            }
            if (Data.DataInput[34] == 1)
            {
                button58.BackColor = Color.Green;
            }
            else
            {
                button58.BackColor = Color.White;
            }
            if (Data.DataInput[35] == 1)
            {
                button83.BackColor = Color.Green;
            }
            else
            {
                button83.BackColor = Color.White;
            }
            if (Data.DataInput[36] == 1)
            {
                button82.BackColor = Color.Green;
            }
            else
            {
                button82.BackColor = Color.White;
            }
            ////////////////////////////////////////////////////////

            if (Data.DataOutput[1] == 0)
            {
                button2.BackColor = Color.Green;
            }
            else
            {
                button2.BackColor = Color.White;
            }
            if (Data.DataOutput[2] == 0)
            {
                button1.BackColor = Color.Green;
            }
            else
            {
                button1.BackColor = Color.White;
            }
            if (Data.DataOutput[3] == 0)
            {
                button3.BackColor = Color.Green;
            }
            else
            {
                button3.BackColor = Color.White;
            }

            if (Data.DataOutput[4] == 0)
            {
                button6.BackColor = Color.Green;
            }
            else
            {
                button6.BackColor = Color.White;
            }

            if (Data.DataOutput[5] == 0)
            {
                button5.BackColor = Color.Green;
            }
            else
            {
                button5.BackColor = Color.White;
            }

            if (Data.DataOutput[6] == 0)
            {
                button4.BackColor = Color.Green;
            }
            else
            {
                button4.BackColor = Color.White;
            }
            if (Data.DataOutput[7] == 0)
            {
                button18.BackColor = Color.Green;
            }
            else
            {
                button18.BackColor = Color.White;
            }

            if (Data.DataOutput[8] == 0)
            {
                button8.BackColor = Color.Green;
            }
            else
            {
                button8.BackColor = Color.White;
            }

            if (Data.DataOutput[9] == 0)
            {
                button16.BackColor = Color.Green;
            }
            else
            {
                button16.BackColor = Color.White;
            }



            if (Data.DataOutput[10] == 0)
            {
                button9.BackColor = Color.Green;
            }
            else
            {
                button9.BackColor = Color.White;
            }


            if (Data.DataOutput[11] == 0)
            {
                button17.BackColor = Color.Green;
            }
            else
            {
                button17.BackColor = Color.White;
            }

            if (Data.DataOutput[12] == 0)
            {
                button7.BackColor = Color.Green;
            }
            else
            {
                button7.BackColor = Color.White;
            }


            if (Data.DataOutput[13] == 0)
            {
                button15.BackColor = Color.Green;
            }
            else
            {
                button15.BackColor = Color.White;
            }
            if (Data.DataOutput[14] == 0)
            {
                button14.BackColor = Color.Green;
            }
            else
            {
                button14.BackColor = Color.White;
            }
            if (Data.DataOutput[15] == 0)
            {
                button37.BackColor = Color.Green;
            }
            else
            {
                button37.BackColor = Color.White;
            }
            if (Data.DataOutput[16] == 0)
            {
                button36.BackColor = Color.Green;
            }
            else
            {
                button36.BackColor = Color.White;
            }



            if (Data.DataOutput[17] == 0)
            {
                button35.BackColor = Color.Green;
            }
            else
            {
                button35.BackColor = Color.White;
            }

            if (Data.DataOutput[18] == 0)
            {
                button31.BackColor = Color.Green;
            }
            else
            {
                button31.BackColor = Color.White;
            }

            if (Data.DataOutput[19] == 0)
            {
                button33.BackColor = Color.Green;
            }
            else
            {
                button33.BackColor = Color.White;
            }
            if (Data.DataOutput[20] == 0)
            {
                button20.BackColor = Color.Green;
            }
            else
            {
                button20.BackColor = Color.White;
            }
            if (Data.DataOutput[21] == 0)
            {
                button34.BackColor = Color.Green;
            }
            else
            {
                button34.BackColor = Color.White;
            }
            if (Data.DataOutput[22] == 0)
            {
                button30.BackColor = Color.Green;
            }
            else
            {
                button30.BackColor = Color.White;
            }
            if (Data.DataOutput[23] == 0)
            {
                button32.BackColor = Color.Green;
            }
            else
            {
                button32.BackColor = Color.White;
            }

            if (Data.DataOutput[24] == 0)
            {
                button12.BackColor = Color.Green;
            }
            else
            {
                button12.BackColor = Color.White;
            }

            if (Data.DataOutput[25] == 0)
            {
                button11.BackColor = Color.Green;
            }
            else
            {
                button11.BackColor = Color.White;
            }

            if (Data.DataOutput[26] == 0)
            {
                button13.BackColor = Color.Green;
            }
            else
            {
                button13.BackColor = Color.White;
            }
            if (Data.DataOutput[27] == 0)
            {
                button85.BackColor = Color.Green;
            }
            else
            {
                button85.BackColor = Color.White;
            }

            if (Data.DataOutput[28] == 0)
            {
                button86.BackColor = Color.Green;
            }
            else
            {
                button86.BackColor = Color.White;
            }

            if (Data.DataOutput[29] == 0)
            {
                button87.BackColor = Color.Green;
            }
            else
            {
                button87.BackColor = Color.White;
            }



            if (Data.DataOutput[30] == 0)
            {
                button90.BackColor = Color.Green;
            }
            else
            {
                button90.BackColor = Color.White;
            }


            if (Data.DataOutput[31] == 0)
            {
                button89.BackColor = Color.Green;
            }
            else
            {
                button89.BackColor = Color.White;
            }

            if (Data.DataOutput[32] == 0)
            {
                button10.BackColor = Color.Green;
            }
            else
            {
                button10.BackColor = Color.White;
            }


            if (Data.DataOutput[33] == 0)
            {
                button94.BackColor = Color.Green;
            }
            else
            {
                button94.BackColor = Color.White;
            }
            if (Data.DataOutput[34] == 0)
            {
                button93.BackColor = Color.Green;
            }
            else
            {
                button93.BackColor = Color.White;
            }
            if (Data.DataOutput[35] == 0)
            {
                button92.BackColor = Color.Green;
            }
            else
            {
                button92.BackColor = Color.White;
            }
            if (Data.DataOutput[36] == 0)
            {
                button91.BackColor = Color.Green;
            }
            else
            {
                button91.BackColor = Color.White;
            }

            if (Data.DataOutput[37] == 0)
            {
                button88.BackColor = Color.Green;
            }
            else
            {
                button88.BackColor = Color.White;
            }

        }

        private void DebugForm_Closing(object sender, CancelEventArgs e)
        {
            timer1.Enabled = false;
        }

        private void DebugForm_Load(object sender, EventArgs e)
        {
            Display();
            for (int i = 0; i < 30; i++)
            {
                Data.DataOutput[i] = 1;
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[1] == 1)
            {
                Data.Send("output#1#0#");

            }
            else
            {
                Data.Send("output#1#1#");

            }
            Display();
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[4] == 1)
            {
                Data.Send("output#4#0#");

            }
            else
            {
                Data.Send("output#4#1#");

            }
            Display();
        }

        private void button18_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[7] == 1)
            {
                Data.Send("output#7#0#");

            }
            else
            {
                Data.Send("output#7#1#");

            }
            Display();
        }

        private void button9_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[10] == 1)
            {
                Data.Send("output#10#0#");

            }
            else
            {
                Data.Send("output#10#1#");

            }
            Display();
        }

        private void button15_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[13] == 1)
            {
                Data.Send("output#13#0#");

            }
            else
            {
                Data.Send("output#13#1#");

            }
            Display();
            left_back = true;
        }

        private void button85_Click_1(object sender, EventArgs e)
        {
            if (Data.DataOutput[27] == 1)
            {
                Data.Send("output#27#0#");

            }
            else
            {
                Data.Send("output#27#1#");

            }
        }

        private void button90_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[30] == 1)
            {
                Data.Send("output#30#0#");

            }
            else
            {
                Data.Send("output#30#1#");

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[2] == 1)
            {
                Data.Send("output#2#0#");

            }
            else
            {
                Data.Send("output#2#1#");

            }
            Display();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[5] == 1)
            {
                Data.Send("output#5#0#");

            }
            else
            {
                Data.Send("output#5#1#");

            }
            Display();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[8] == 1)
            {
                Data.Send("output#8#0#");

            }
            else
            {
                Data.Send("output#8#1#");

            }
            Display();
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[11] == 1)
            {
                Data.Send("output#11#0#");

            }
            else
            {
                Data.Send("output#11#1#");

            }
            Display();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[14] == 1)
            {
                Data.Send("output#14#0#");

            }
            else
            {
                Data.Send("output#14#1#");

            }
            Display();
        }

        private void button86_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[28] == 1)
            {
                Data.Send("output#28#0#");

            }
            else
            {
                Data.Send("output#28#1#");

            }
        }

        private void button89_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[31] == 1)
            {
                Data.Send("output#31#0#");

            }
            else
            {
                Data.Send("output#31#1#");

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[3] == 1)
            {
                Data.Send("output#3#0#");

            }
            else
            {
                Data.Send("output#3#1#");

            }
            Display();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[6] == 1)
            {
                Data.Send("output#6#0#");

            }
            else
            {
                Data.Send("output#6#1#");

            }
            Display();
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[9] == 1)
            {
                Data.Send("output#9#0#");

            }
            else
            {
                Data.Send("output#9#1#");

            }
            Display();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[12] == 1)
            {
                Data.Send("output#12#0#");

            }
            else
            {
                Data.Send("output#12#1#");

            }
            Display();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[26] == 1)
            {
                Data.Send("output#26#0#");

            }
            else
            {
                Data.Send("output#26#1#");

            }
            Display();
        }

        private void button87_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[29] == 1)
            {
                Data.Send("output#29#0#");

            }
            else
            {
                Data.Send("output#29#1#");

            }
        }

        private void button37_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[15] == 1)
            {
                Data.Send("output#15#0#");

            }
            else
            {
                Data.Send("output#15#1#");

            }
            Display();
        }

        private void button31_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[18] == 1)
            {
                Data.Send("output#18#0#");

            }
            else
            {
                Data.Send("output#18#1#");

            }
            Display();
        }

        private void button34_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[21] == 1)
            {
                Data.Send("output#21#0#");

            }
            else
            {
                Data.Send("output#21#1#");

            }
            Display();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[24] == 1)
            {
                Data.Send("output#24#0#");

            }
            else
            {
                Data.Send("output#24#1#");

            }
            Display();
        }

        private void button94_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[33] == 1)
            {
                Data.Send("output#33#0#");

            }
            else
            {
                Data.Send("output#33#1#");

            }
        }

        private void button91_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[36] == 1)
            {
                Data.Send("output#36#0#");

            }
            else
            {
                Data.Send("output#36#1#");

            }
        }

        private void button36_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[16] == 1)
            {
                Data.Send("output#16#0#");

            }
            else
            {
                Data.Send("output#16#1#");

            }
            Display();
        }

        private void button33_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[19] == 1)
            {
                Data.Send("output#19#0#");

            }
            else
            {
                Data.Send("output#19#1#");

            }
            Display();
        }

        private void button30_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[22] == 1)
            {
                Data.Send("output#22#0#");

            }
            else
            {
                Data.Send("output#22#1#");

            }
            Display();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[25] == 1)
            {
                Data.Send("output#25#0#");

            }
            else
            {
                Data.Send("output#25#1#");

            }
            Display();
        }

        private void button93_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[34] == 1)
            {
                Data.Send("output#34#0#");

            }
            else
            {
                Data.Send("output#34#1#");

            }
        }

        private void button88_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[37] == 1)
            {
                Data.Send("output#37#0#");

            }
            else
            {
                Data.Send("output#37#1#");

            }
        }

        private void button35_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[17] == 1)
            {
                Data.Send("output#17#0#");

            }
            else
            {
                Data.Send("output#17#1#");

            }
            Display();
        }

        private void button20_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[20] == 1)
            {
                Data.Send("output#20#0#");

            }
            else
            {
                Data.Send("output#20#1#");

            }
            Display();
        }

        private void button32_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[23] == 1)
            {
                Data.Send("output#23#0#");

            }
            else
            {
                Data.Send("output#23#1#");

            }
            Display();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[32] == 1)
            {
                Data.Send("output#32#0#");

            }
            else
            {
                Data.Send("output#32#1#");

            }
        }

        private void button92_Click(object sender, EventArgs e)
        {
            if (Data.DataOutput[35] == 1)
            {
                Data.Send("output#35#0#");

            }
            else
            {
                Data.Send("output#35#1#");

            }
        }

        private void button45_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button43_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox3.Text != "")
                {
                    if (Data.DataOutput[42] == 0)
                    {
                        Data.Send("output#42#1#" + textBox3.Text + "#");

                    }
                    else
                    {
                        Data.Send("output#42#0#");

                    }
                }


            }
            catch
            {

            }
        }
    }
}